<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It is a breeze. Simply tell Lumen the URIs it should respond to
| and give it the Closure to call when that URI is requested.
|
 */
$api = app('Dingo\Api\Routing\Router');

// v1 version API
// add in header    Accept:application/vnd.lumen.v1+json
$api->version('v1', [
    'namespace' => 'App\Http\Controllers\Api\V1\Base',
    'middleware' => [
        'cors',
        'serializer',
        //'serializer:array', // if you want to remove data wrap
        'api.throttle',
    ],
    // each route have a limit of 20 of 1 minutes
    'limit' => 20, 'expires' => 1,
], function ($api) {
    // Auth
    // login

    // base base
    //wechat code login
    $api->post('base/wechatcode', [
        'as' => 'base.login.wechatcode',
        'uses' => 'WechatLoginController@getOpenid',
    ]);

    // phone login
    $api->post('base/login', [
        'as' => 'base.login.login',
        'uses' => 'LoginController@index',
    ]);

    // mini_program login
    $api->post('base/minicode', [
        'as' => 'base.login.minicode',
        'uses' => 'MiniProgramLoginController@getOpenid',
    ]);

    // 发送短信验证码
    $api->post('base/code', [
        'as' => 'base.login.code',
        'uses' => 'LoginController@code',
    ]);

    // banners
    $api->get('base/banners', [
        'as' => 'base.banner.index',
        'uses' => 'BannerController@index',
    ]);
    // activitys
    $api->get('base/activitys', [
        'as' => 'base.activity.index',
        'uses' => 'ActivityController@index',
    ]);

    //发送反馈图片
    $api->post('base/feedback/uploadimg', [
        'as' => 'base.feedback.uploadimg',
        'uses' => 'FeedbackController@uploadimg',
    ]);

    //得到反馈列表
    $api->get('base/feedbacks', [
        'as' => 'base.feedback.list',
        'uses' => 'FeedbackController@userFeedbacks',
    ]);

    //得到积分规则
    $api->get('base/pointrule', [
        'as' => 'base.point.pointrule',
        'uses' => 'PointRuleController@index',
    ]);

    //积分商品列表
    $api->get('base/pointgoodslist', [
        'as' => 'base.pointgoods.list',
        'uses' => 'PointGoodsController@index',
    ]);

    //积分商品详情
    $api->get('base/pointgoodswithinlist', [
        'as' => 'base.pointgoods.show',
        'uses' => 'PointGoodsController@showlist',
    ]);

    //积分商品详情
    $api->get('base/pointgoods/{id}', [
        'as' => 'base.pointgoods.show',
        'uses' => 'PointGoodsController@show',
    ]);


    // member/aboutus list
    $api->get('base/index', [
        'as' => 'base.aboutus.index',
        'uses' => 'AboutUsController@index',
    ]);

    // base/aboutus detail
    $api->get('base/show', [
        'as' => 'base.aboutus.show',
        'uses' => 'AboutUsController@show',
    ]);
    $api->get('base/about_rule', [
        'as' => 'base.aboutus.about_rule',
        'uses' => 'AboutUsController@about_rule',
    ]);
    $api->get('base/contact', [
        'as' => 'base.aboutus.contact',
        'uses' => 'AboutUsController@contact',
    ]);
    $api->get('base/memberRights', [
        'as' => 'base.aboutus.memberRights',
        'uses' => 'AboutUsController@memberRights',
    ]);
    $api->get('base/help', [
        'as' => 'base.aboutus.help',
        'uses' => 'AboutUsController@help'
    ]);
    $api->get('help-info/{id}', [
        'as' => 'base.aboutus.helpInfo',
        'uses' => 'AboutUsController@helpInfo'
    ]);

    // need authentication
    $api->group(['middleware' => 'api.auth'], function ($api) {
        /*
         * 对于authorizations 并没有保存在数据库，所以并没有id，那么对于
         * 刷新（put) 和 删除（delete) 我没有想到更好的命名方式
         * 所以暂时就是 authorizations/current 表示当前header中的这个token。
         * 如果 tokekn 保存保存在数据库，那么就是 authorizations/{id}，像 github 那样。
         */

        // jwt base

        // 绑定phone
        $api->post('base/phone', [
            'as' => 'base.login.phone',
            'uses' => 'LoginController@phone',
        ]);

        //更改电话
        $api->post('base/updatephone', [
            'as' => 'base.login.updatephone',
            'uses' => 'LoginController@updatePhone',
        ]);

        //活动详情
        $api->get('base/activity/{id}', [
            'as' => 'base.activity.show',
            'uses' => 'ActivityController@show',
        ]);

        //参加活动
        $api->post('base/activity/{id}', [
            'as' => 'base.activity.store',
            'uses' => 'ActivityController@store',
        ]);


        // 消息列表
        $api->get('base/messages', [
            'as' => 'base.message.index',
            'uses' => 'MessageController@index',
        ]);
        // 消息详情
        $api->get('base/message/{id}', [
            'as' => 'base.message.show',
            'uses' => 'MessageController@show',
        ]);
        //发送消息
        $api->post('base/message', [
            'as' => 'base.message.store',
            'uses' => 'MessageController@store',
        ]);

        //发送反馈
        $api->post('base/feedback', [
            'as' => 'base.feedback.store',
            'uses' => 'FeedbackController@store',
        ]);

        //用户积分列表
        $api->get('base/memberpoints', [
            'as' => 'base.memberpoint.list',
            'uses' => 'PointLogController@index',
        ]);

        //用户积分详情
        $api->get('base/memberpoint/{id}', [
            'as' => 'base.memberpoint.show',
            'uses' => 'PointLogController@show',
        ]);

        //用户积分订单列表
        $api->get('base/pointorders', [
            'as' => 'base.pointorder.list',
            'uses' => 'PointOrderController@index',
        ]);
        //用户积分订单详情
        $api->get('base/pointorder/{id}', [
            'as' => 'base.pointorder.show',
            'uses' => 'PointOrderController@show',
        ]);

        //用户提交积分订单
        $api->post('base/pointorder', [
            'as' => 'base.pointorder.store',
            'uses' => 'PointOrderController@store',
        ]);

        /*
         * 支付相关
         */
        // 创建订单号
        $api->post('base/create-order', [
            'as' => 'base.order.create-order',
            'uses' => 'OrderController@createOrder'
        ]);

    });
});
